package com.xuning.emperor.business.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuning.emperor.base.BusinessImpl;
import com.xuning.emperor.business.IProductBusiness;
import com.xuning.emperor.business.IUserBusiness;
import com.xuning.emperor.converter.ProductConverter;
import com.xuning.emperor.converter.UserConverter;
import com.xuning.emperor.domain.dto.ProductDTO;
import com.xuning.emperor.domain.dto.UserDTO;
import com.xuning.emperor.domain.po.Product;
import com.xuning.emperor.domain.po.User;
import com.xuning.emperor.domain.vo.ProductVO;
import com.xuning.emperor.domain.vo.UserVO;
import com.xuning.emperor.service.IProductService;
import com.xuning.emperor.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @author wangqx
 * @description 用户业务层
 * @date 2022/6/16
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class ProductBusinessImpl extends BusinessImpl<IProductService, ProductConverter, ProductVO, ProductDTO, Product> implements IProductBusiness {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(ProductDTO dto) {
        service.save(converter.toPO( dto));
        return true;
    }

    @Override
    public List<ProductVO> list(ProductDTO d) {
        List<Product> productList=service.list();
        return converter.toVO(productList);
    }

    @Override
    public IPage<ProductVO> page(IPage<ProductVO> page, ProductDTO d) {

        Page<Product> poPage=new Page<Product>();
        poPage.setSize(page.getSize());
        poPage.setCurrent(page.getCurrent());
        Page<Product> userPage=service.page(poPage,new QueryWrapper<Product>());
        return converter.toVO(userPage);
    }

    @Override
    public ProductVO get(Serializable id) {
        return converter.toVO(service.getById(id));
    }

    @Override
    public boolean delete(Serializable id) {
        return service.removeById(id);
    }
}
